 export function setCookie(key, value, expires) {
    if (!key || !value) {
        throw Error("key 和 value是必填");
    }
    // 判断是否有过期时间
    if (!expires) {
        document.cookie = `${key}=${value};path=/;`;
        return;
    }

    let date = new Date();
    let time = date.getTime() - 8 * 60 * 60 * 1000 + expires * 60 * 1000;
    date.setTime(time); // 根据时间戳得到这个时间戳的时间对象
    document.cookie = `${key}=${value};path=/;expires=${date}`;
}


export function getCookie(key) {
    let cookie = document.cookie;
    let arr = cookie.split("; ");
    let obj = {};
    arr.forEach((item) => {
        let res = item.split("=");
        obj[res[0]] = res[1];
    });

    if (!key) return obj;

    return obj[key];
}
